<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>

        <ui:composition template="../templates/default3.xhtml">  

            <ui:define name="content">
                <h:form binding="#{salesOrderManagerBean.loadViewSalesOrderPage}">
                    <p:panel header="Quotation Items" id="quotationItemsPanel">
                        <p:messages/>
                        <h:outputText value="Quotation #{salesOrderManagerBean.selectedQuotation.id}
                                      has a total value of "/>
                        <h:outputText value="#{salesOrderManagerBean.selectedQuotation.totalAmount}">
                            <f:convertNumber type="currency"/>
                        </h:outputText>
                        <hr/>
                        <p:dataTable id="quotationItems" var="quotationItem" value="#{salesOrderManagerBean.selectedQuotation.quotationItems}" 
                                     emptyMessage="No quotation items found with given criteria.">
                            <p:column filterBy="#{quotationItem.product.name}" headerText="Product" 
                                      filterMatchMode="contains" sortBy="#{quotationItem.product.name}">  
                                <h:outputText value="#{quotationItem.product.name}"/> 
                            </p:column> 
                            <p:column filterBy="#{quotationItem.unitPrice}" headerText="Unit Price" 
                                      filterMatchMode="contains" sortBy="#{quotationItem.unitPrice}">  
                                <h:outputText value="#{quotationItem.unitPrice}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:column filterBy="#{quotationItem.quantity}" headerText="Quantity" 
                                      filterMatchMode="contains" sortBy="#{quotationItem.quantity}">  
                                <h:outputText value="#{quotationItem.quantity}"/> 
                            </p:column> 
                            <p:column filterBy="#{quotationItem.discount}" headerText="Discount (%)" 
                                      filterMatchMode="contains" sortBy="#{quotationItem.discount}">  
                                <h:outputText value="#{quotationItem.discount}">

                                </h:outputText>
                            </p:column> 

                            <p:column filterBy="#{quotationItem.shippingRate}" headerText="Shipping" 
                                      filterMatchMode="contains" sortBy="#{quotationItem.shippingRate}">  
                                <h:outputText value="#{quotationItem.shippingRate}"> 
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 

                            <p:column filterBy="#{quotationItem.subTotal}" headerText="Subtotal" 
                                      filterMatchMode="contains" sortBy="#{quotationItem.subTotal}">  
                                <h:outputText value="#{quotationItem.subTotal}" >  
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:columnGroup type="footer">  
                                <p:row>  
                                    <p:column colspan="5" footerText="Total:" style="text-align:right"/>
                                    <p:column footerText="$ #{salesOrderManagerBean.selectedQuotation.totalAmount}"/>
                                </p:row>  
                            </p:columnGroup>  
                        </p:dataTable>
                    </p:panel>
                    <p:panel header="Purchase Order Items" id="purchaseOrderItemsPanel">
                        <h:outputText value="Purchase order #{salesOrderManagerBean.selectedPurchaseOrder.poNumber}
                                      has a total value of "/> 
                        <h:outputText value="#{salesOrderManagerBean.selectedPurchaseOrder.totalAmount}"> 
                            <f:convertNumber type="currency"/>
                        </h:outputText>
                        <hr/>
                        <p:dataTable id="purchaseOrderItems" var="purchaseOrderItem" value="#{salesOrderManagerBean.selectedPurchaseOrder.purchaseItems}" 
                                     emptyMessage="No purchase order items found with given criteria.">
                            <p:column filterBy="#{purchaseOrderItem.product.name}" headerText="Product" 
                                      filterMatchMode="contains" sortBy="#{quotationItem.product.name}">  
                                <h:outputText value="#{purchaseOrderItem.product.name}"/> 
                            </p:column> 
                            <p:column filterBy="#{purchaseOrderItem.unitPrice}" headerText="Unit Price" 
                                      filterMatchMode="contains"  sortBy="#{quotationItem.unitPrice}">  
                                <h:outputText value="#{purchaseOrderItem.unitPrice}">  
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:column filterBy="#{purchaseOrderItem.quantity}" headerText="Quantity" 
                                      filterMatchMode="contains" sortBy="#{quotationItem.quantity}">  
                                <h:outputText value="#{purchaseOrderItem.quantity}"/> 
                            </p:column> 
                            <p:column filterBy="#{purchaseOrderItem.discount}" headerText="Discount (%)" 
                                      filterMatchMode="contains" sortBy="#{purchaseOrderItem.discount}">  
                                <h:outputText value="#{purchaseOrderItem.discount}">  

                                </h:outputText>
                            </p:column> 

                            <p:column filterBy="#{purchaseOrderItem.shippingRate}" headerText="Shipping" 
                                      filterMatchMode="contains" sortBy="#{purchaseOrderItem.shippingRate}">  
                                <h:outputText value="#{purchaseOrderItem.shippingRate}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 

                            <p:column filterBy="#{purchaseOrderItem.subTotal}" headerText="Subtotal" 
                                      filterMatchMode="contains" sortBy="#{purchaseOrderItem.subTotal}">  
                                <h:outputText value="#{purchaseOrderItem.subTotal}">  
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:columnGroup type="footer">  
                                <p:row>  
                                    <p:column colspan="5" footerText="Total:" style="text-align:right"/>
                                    <p:column footerText="$ #{salesOrderManagerBean.selectedPurchaseOrder.totalAmount}"/>
                                </p:row>  
                            </p:columnGroup>  
                        </p:dataTable>
                       



                        <p:confirmDialog  width="400" message="" header="Rejecting a sales order" severity="alert" widgetVar="confirmation">
                            <f:facet name="message">
                                <h:outputText value="Rejecting this sales order will stop any related processes for the order"/><br/>
                                <h:outputText value="Are you sure you want to continue?"/>
                            </f:facet>    
                            <p:commandButton value="Yes" update="quotationItemsPanel" oncomplete="confirmation.hide()"
                                             actionListener="#{salesOrderManagerBean.rejectSalesOrder}"/>
                            <p:commandButton value="No" update="quotationItemsPanel" onclick="confirmation.hide()" type="button" />
                        </p:confirmDialog>
                        <p:confirmDialog  width="400" message="" header="Approving a sales order" severity="alert" widgetVar="confirmation2">
                            <f:facet name="message">
                                <h:outputText value="Approving this sales order will trigger other finance and warehouse related processes."/><br/>
                                <h:outputText value="Are you sure you want to continue?"/>
                            </f:facet>    
                            <p:commandButton value="Yes" update="quotationItemsPanel" oncomplete="confirmation2.hide()"
                                             actionListener="#{salesOrderManagerBean.approveSalesOrder}"/>
                            <p:commandButton value="No" update="quotationItemsPanel" onclick="confirmation2.hide()" type="button" />
                        </p:confirmDialog>
                    </p:panel>

                    <p:panel header="Remark" id="purchaseOrderItemsPanel2">
                        <table width="100%">


                            <tr>
                                <td> <p:inputTextarea id="remark" style="width:815px;height:150px;overflow:scroll" maxHeight="150" effectDuration="400" readonly="true" value="#{salesOrderManagerBean.remark}">

                                    </p:inputTextarea>    </td>
                            </tr>
                        </table>

                    </p:panel>
                    <hr></hr>
                    <center> <p:commandButton id="btnRejectSalesOrder" value="Reject Sales Order" 
                                         onclick="confirmation.show()" type="button"/>
                        <p:commandButton id="btnApproveSalesOrder" value="Approve Sales Order" 
                                         onclick="confirmation2.show()" type="button"/></center>
                        

                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
